﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class OrderInfoBLL
    {
        private OrderInfoDAL _orderInfo = new OrderInfoDAL();
        public int AddOrderInfo(OrderInfo orderInfo)
        {
           return _orderInfo.AddOrderInfo(orderInfo);
        }


        public int AddOrderAndDeskInfo(int ordId, int deskId)
        {
            return _orderInfo.AddOrderAndDeskInfo(ordId, deskId);
        }


        public DataTable SelectProductByOrder(int orderId)
        {
            return _orderInfo.SelectProductByOrder(orderId);
        }


        public int AddOrderProducts(Order_ProductDTO order_ProductDTO)
        {
            //判断商品是否已经添加
            int count = _orderInfo.SelectProCountByOrder(order_ProductDTO);
            if(count > 0)
            {
                return _orderInfo.UpdateOrderProducts(order_ProductDTO);
            }

            return _orderInfo.AddOrderProducts(order_ProductDTO);
        }
        

        public void SelectOrderCountAndPrice(OrderDTO orderDTO, out int count, out int price)
        {
            count = _orderInfo.SelectOrderPCount(orderDTO);
            price = _orderInfo.SelectOrderPrice(orderDTO);
        }


        //根据桌子编号查询最新订单编号
        public int SelectOrderIdByDeskId(int deskId)
        {
            return _orderInfo.SelectOrderIdByDeskId(deskId);
        }

        //修改订单中的商品数量
        public int UpdateProCountByOrderId(int oid, int pid)
        {
            int count = _orderInfo.SelectProCountByOrderId(oid, pid);
            if (count > 1)
            {
                return _orderInfo.UpdateProCountByOrderId(oid, pid);
            }

            return _orderInfo.DeleteProCountByOrderId(oid, pid);

        }


        //结账
        public int CheckOut(int oid, double money, double discount)
        {
            return _orderInfo.CheckOut(oid, money, discount);
        }




    }
}
